package com.lc.controller;

import com.lc.dto.ResponseJson;
import com.lc.service.ITestService;
import com.lc.service.ITestServiceProvider;
import com.lc.utils.KingProxy;
import com.lc.utils.MyApplicationContext;
import com.lc.utils.PostProcessorBean;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lichao on 2017/5/5.
 */
@Controller
@RequestMapping(value="T")
public class TestController {

    @Resource(name = "ITestService")
    private ITestService iTestService;

    @RequestMapping(value="/getData",method = RequestMethod.POST)
    @ResponseBody
    public ResponseJson getData(@Param("id") String id){
        ResponseJson result = new ResponseJson();
        List list = iTestService.getData(Integer.parseInt(id));
        Map map = new HashMap<String,Object>();
        map.put("result",list);
        result.setBody(map);
        return result;
    }
    @RequestMapping(value="/getRedisData",method = RequestMethod.POST)
    @ResponseBody
    public ResponseJson getRedisData(@Param("key") String key, HttpServletRequest request){
        ResponseJson result = new ResponseJson();
        List list = iTestService.getRedisData(key);
        Map map = new HashMap<String,Object>();
        map.put("result",list);
        result.setBody(map);
        return result;
    }
    @RequestMapping(value="/getProviderData",method = RequestMethod.POST)
    @ResponseBody
    public ResponseJson getProviderData(@Param("key") String key){
        ResponseJson result = new ResponseJson();
        //String s = iTestService.getProviderData(key);
        Map map = new HashMap<String,Object>();
        Object o = MyApplicationContext.getApplicationContext().getBeanDefinitionNames();
        /*KingProxy kingProxy = (KingProxy)MyApplicationContext.getBean("kingProxy");
        Object bean = MyApplicationContext.getBean("ITestService");
        kingProxy.setTarget(bean);
        ITestService ss = (ITestService)Proxy.newProxyInstance(bean.getClass().getClassLoader(),bean.getClass().getInterfaces(),kingProxy);
        List s = ss.getRedisData(key);*/
        //String s = ss.TestMethod(key);
        /*map.put("userName",postProcessorBean.getUsername());
        map.put("passWord",postProcessorBean.getPassword());*/
        map.put("name",o);
        //map.put("result",s);
        result.setBody(map);
        return result;
    }
    @PostConstruct
    public void init(){
        System.out.println("______________controller_______________");
    }

}
